package com.example.contact

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.ui.unit.ExperimentalUnitApi
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import com.example.contact.view.ContactDetailScreen
import com.example.contact.view.ContactListView
import com.example.contact.view.ContactSearchView
import com.example.featuresdk.core.AbstractFeatureSDK
import com.example.featuresdk.viewmodel.NavigationViewModel


@ExperimentalFoundationApi
@OptIn(ExperimentalUnitApi::class)
fun NavGraphBuilder.contactNestedNavigationGraph(navigationViewModel: NavigationViewModel,
                                                 featureSDK: AbstractFeatureSDK) {

    val featureKey = featureSDK.featureKey()

    navigation(startDestination = "${featureKey}/list", route = "$featureKey") {

        composable("${featureKey}/list") {
            ContactListView(navigationViewModel, featureSDK)
        }

        composable("${featureKey}/search") {
            ContactSearchView(navigationViewModel, featureSDK)
        }

        composable("${featureKey}/contact/{contactKey}") { navBackStackEntry ->
            ContactDetailScreen(navBackStackEntry.arguments?.getString("contactKey"), navigationViewModel, featureSDK)
        }
    }
}